import multiprocessing
multiprocessing.freeze_support()
import os
import shutil

import yolo
from client.tdmg import manager
from dataTemp.user import User, Role
from process.copyBWJ import CopyBWJ
from taskPro import taskPro
from ui.mainUI import MainUI, run_main_ui


def delete_all_subfolders(target_folder):
    # 检查目标文件夹是否存在
    if not os.path.exists(target_folder):
        print(f"Target folder '{target_folder}' does not exist.")
        return

    # 遍历目标文件夹下的所有项
    for item in os.listdir(target_folder):
        item_path = os.path.join(target_folder, item)

        # 如果是文件夹，则删除它
        if os.path.isdir(item_path):
            shutil.rmtree(item_path)
            # print(f"Deleted folder: {item_path}")


def teat(stop_event):
    yolo.get_prop("")
    # while not stop_event.is_set():
    #     yolo.get_prop("")


if __name__ == "__main__":
    taskPro.initAction(".\\tasks\\actions")
    delete_all_subfolders("./runs/detect")
    user = User()
    user.brick_roles = [Role(6, "奶妈", 8), Role(7, "百花", 8),
                        Role(5, "阿修罗", 8), Role(1, "鬼泣", 10)]

    # taskPro.getAction("entryGame").click()
    # taskPro.getAction("entryGame2w").click()
    # yolo.get_prop("")
    manager.start_thread(target=teat, args=(manager.get_stop_event(),))
    run_main_ui(user)

    # Mes("0","1")
    # bwj = CopyBWJ(user)
    print(f"任务完成。/。。。。。。。。。。。。")
    # manager.stop_all_threads()
    # manager.clear_threads()
